// import {xcflowGenerateRequestUrl} from '@/utils/xcflow'


export function xcflowGenerateRequestUrl(vm, url) {
  let clogintoken = vm.$route.query.clogintoken;

  let xcbaseurl = vm.$route.query.xcbaseurl;

  let sep = "?";
  if (url.indexOf("?") >= 0) {
    sep = "&";
  }

  return xcbaseurl + '/' + url + sep + "clogintoken=" + clogintoken;
}

export function xcflowGetPreveiwOptions(vm, csmoptions, func) {
  let resultOptions = [];
  switch (csmoptions['optionSource']) {
    case "static":
      let list = csmoptions['options'];
      for (let index in list) {
        resultOptions.push({
          value: list[index]['value']
        });
      }
      func(resultOptions);
      break;
    case "mdmdata":
      let url = xcflowGenerateRequestUrl(vm, "getMdmDatas?xcflowmdm_id=" + csmoptions['option_xcflowmdmdata_id']);
      let method = 'get';
      vm.$axios({
        method,
        url,
        headers: {
          'X-Requested-With': 'XMLHttpRequest'
        },
      }).then(resp => {
        let list = resp.data.data.list;
        for (let index in list) {
          resultOptions.push({
            value: list[index]['title']
          });
        }
        func(resultOptions);
      });
      break;
  }
}
